package com.mf.ergate.web.domain.model;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

/**
 * MenuTree实体
 * User: zhaoming
 * Date: 15-11-4 Time: 下午11:20 To change this template
 * use File | Settings | File Templates.
 */
public class MenuTree implements Serializable {

	/**
	 * 序列化
	 */
	private static final long serialVersionUID = 1L;

	private String id;
	private String code;
	private String name;
	private String icon;
	private String url;
	private String parentId;
	private int order;
	private List<MenuTree> menus = new LinkedList<MenuTree>();

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public List<MenuTree> getMenus() {
		return menus;
	}

	public void setMenus(List<MenuTree> menus) {
		this.menus = menus;
	}

	public void addChildMenu(MenuTree tree) {
		if (this.menus.size() == 0) {
			this.menus.add(tree);
		} else {
			int myOrder = tree.getOrder();
			for (int i = 0; i < this.menus.size(); i++) {
				int order = this.menus.get(i).getOrder();
				if(myOrder <= order){
					this.menus.add(i, tree);
					break;
				} else if (i == this.menus.size() - 1){
					this.menus.add(tree);
					break;
				} else {
					continue;
				}
			}
		}
	}

	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	public int getOrder() {
		return order;
	}

	public void setOrder(int order) {
		this.order = order;
	}
}
